package org.tokaf.datasearcher;

import org.openrdf.sesame.Sesame;
import org.openrdf.sesame.config.ConfigurationException;
import org.openrdf.sesame.config.RepositoryConfig;
import org.openrdf.sesame.config.SailConfig;
import org.openrdf.sesame.constants.RDFFormat;
import org.openrdf.sesame.repository.local.LocalService;

/**
 * <p>Uses Sesame in file mode. It creates virtual database in memory and load file in it.</p>
 * <p>Copyright (c) 2006</p>
 * @author Alan Eckhardt
 * @version 1.0
 */
public class SesameFileSearcher extends SesameSearcher {

	public SesameFileSearcher() {
	}

	public int initSource(String db) {
		return initSource(db, RDFFormat.RDFXML);
	}

	public Object clone() {
		SesameFileSearcher newInstance = new SesameFileSearcher();
		newInstance.initSource(this);
		newInstance.results = this.results;
		newInstance.columnCount = this.columnCount;
		newInstance.index = this.index;
		newInstance.searchIndex = this.searchIndex;
		newInstance.query = this.query;
		return newInstance;
	}

	public int initSource(String db, RDFFormat format) {
		long startTime = System.nanoTime();
		LocalService service = Sesame.getService();
		//service.cre
		//boolean inferencing = true;

		RepositoryConfig repConfig = new RepositoryConfig("myCustomRep");
		SailConfig syncSail = new SailConfig(
				"org.openrdf.sesame.sailimpl.sync.SyncRdfSchemaRepository");
		SailConfig memSail = new org.openrdf.sesame.sailimpl.memory.RdfSchemaRepositoryConfig(
				db, format);
		repConfig.addSail(syncSail);
		repConfig.addSail(memSail);
		repConfig.setWorldReadable(true);
		repConfig.setWorldWriteable(true);
		try {
			myRepository = service.createRepository(repConfig);
			/*myRepository = service.createRepository(db,inferencing);
			 File myfile1 = new File (db);

			 String baseURI = "http://www.muaddib.wz.cz/";
			 boolean verifyData = true;
			 AdminListener myListener = new StdOutAdminListener ();

			 myRepository.addData (myfile1, baseURI, RDFFormat.RDFXML, verifyData, myListener);
			 */
		} catch (ConfigurationException ex) {
		}
		initSourceTime = System.nanoTime() - startTime;
		return 1;
	}

}
